package com.baidu.customview.widget;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by imagine on 2015/9/29.
 */
public class HeadView extends View {
    Paint paint=new Paint();
    public HeadView(Context context) {
        super(context);
    }

    public HeadView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public HeadView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public HeadView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
//        draw a circle
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(10);
        canvas.drawCircle(300, 300, 300, paint);
//        draw several lines
        canvas.drawLine(60, 120, 540, 120, paint);
        canvas.drawLine(300, 120, 60, 480, paint);
        canvas.drawLine(300, 120, 540, 480, paint);

//        draw two eyes
        paint.setStyle(Paint.Style.FILL);
        canvas.drawCircle(60, 180, 30, paint);
        RectF r2=new RectF(510,150,570,210);
        canvas.drawArc(r2,270,90,true,paint);
//        draw a mouth
        paint.setStyle(Paint.Style.STROKE);
        RectF r1=new RectF(240,420,360,480);
        canvas.drawRect(r1, paint);

//        draw a signature
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(2);
        paint.setColor(Color.BLUE);
        paint.setTextSize(100);
        canvas.drawText("It`s me",100,700,paint);
    }
}
